﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bouyei.GeoCore.GeoParsers.GeoJson
{
    public class LineMArray :IArray<LineArray>
    {
        private int position = 0;

        private List<LineArray> Array;

        public LineMArray()
        {

        }

        public LineMArray(int capacity)
        {
            Array = new List<LineArray>(capacity);
        }

        public void FromWkt(string wkt)
        {
            Wkt.GeometryReader parser =
                 new Wkt.GeometryReader(wkt);

            var ls = parser.ReaderCoodinates();
            if (ls.Count == 0) return;

            var coords = ls[0];
            Array = new List<LineArray>(coords.Count);

            for (int i = 0; i < coords.Count; i++)
            {
                var line = new LineArray(coords[i].Length);
                line.FromArray(coords[i]);
                Array.Add(line);
            }
        }

        public object Current => Array[position];

        public LineArray this[int index]
        {
            get { return Array[index]; }
            set { Array[index] = value; }
        }

        public bool MoveNext()
        {
            ++position;
            return position < Array.Count;
        }

        public void Reset()
        {
            position = 0;
        }

        public IEnumerator<LineArray> GetEnumerator()
        {
            foreach (var item in Array)
                yield return item;
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            foreach (var item in Array)
                yield return item;
        }
    }
}
